﻿using Microsoft.AspNetCore.Mvc;
using Zhp.Api.Attributes;
using Zhp.Auth;
using Zhp.IService.Sys;
using Zhp.Model.Common;
using Zhp.Model.Sys;

namespace Zhp.Api.Controllers.Sys
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [ApiGroup(GroupName = ApiGroupEnum.Sys)]
    public class SysUserMenuController : ControllerBase
    {
        protected readonly ISysUserMenuService SysUserMenu;

        public SysUserMenuController(ISysUserMenuService SysUserMenu)
        {
            this.SysUserMenu = SysUserMenu;
        }

        [SeedButton("分配菜单", "用户列表", "用户管理", ApiGroupEnum.Sys)]
        [HttpGet("{userId}")]
        public async Task<ListRet<UserMenuModel>> Index(long userId)
        {
            var (userMenulist, menuList) = await SysUserMenu.GetUserMenu(userId);
            
            return new ListRet<UserMenuModel>
            {
                DataList = userMenulist,
                DataExt = menuList
            };
        }

        [SeedButton("分配菜单:保存", "用户列表", "用户管理", ApiGroupEnum.Sys)]
        [HttpPost]
        public async Task<bool> Create(UserMenuCreate create)
        {
            return await SysUserMenu.Create(create);
        }
    }
}
